package com.production.CoursePlatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.production.CoursePlatform.entity.Discussion;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DiscussionMapper extends BaseMapper<Discussion> {
    //使用s_id, ct_id, d_tag, d_title, d_content创建帖子
    @Insert("INSERT INTO discussion (sId, ctId, dTag, dTitle, dContent,dTime) " +
            "VALUES (#{sId}, #{ctId}, #{dTag}, #{dTitle}, #{dContent},#{dTime})")
    int insertWithoutDID(Discussion discussion);

    //提供ct_id获得对应的帖子列表
    @Select("SELECT dId FROM discussion WHERE ctId = #{ctID}")
    List<Discussion> getPostBYctID(int ctID);

    // 根据d_id增加d_likes
    @Update("UPDATE discussion SET dLikes = dLikes + 1 WHERE dId = #{dID}")
    int incrementLikes(@Param("dID") int dID);

    // 根据d_id增加d_comments
    @Update("UPDATE discussion SET dComments = dComments + 1 WHERE dId = #{dID}")
    int incrementComments(@Param("dID") int dID);

    // 根据d_id增加d_favorites
    @Update("UPDATE discussion SET dFavorites = dFavorites + 1 WHERE dId = #{dID}")
    int incrementFavorites(@Param("dID") int dID);

    // 删除帖子
    @Delete("DELETE FROM discussion WHERE dId = #{dID}")
    int deleteById(@Param("dID") int dID);
}
